#!/usr/bin/python
# -*- coding: utf-8 -*-
# author: yoshiii.yoshiii@googlemail.com
# you found this code on http://yoshiii-box.googlecode.com/svn/ 
#

import os, sys

prefix = ".fec"
suffix = ".par2"

command = {
	"create" : "par2 create -u %s *"%prefix,
	"verify" : "par2 verify %s"%prefix,
	"repair" : "par2 repair %s"%prefix,
	}

def visit(cmd, dirname, names):
	print "visit", cmd, dirname, names
	if cmd == "create":
		assert prefix+suffix not in names, "can't create " + prefix+suffix + " already exists"
	os.chdir(dirname)
	print "curdir:", os.getcwd()
	print "cmd:", command[cmd]
	os.system(command[cmd])

def create_recursive(path):
	os.path.walk(path, visit, "create")

def main():

	path = "."
	cmd = "create"
	
	if len(sys.argv) > 1:
		path = sys.argv[1]
	print "path:", path

	os.chdir(path)

	print "pwd", os.getcwd()

	os.path.walk(path, visit, cmd)


if __name__ == '__main__':
	main()

